import { AssetacquisitionManageAPI } from '../common/type';
import { Button, Tooltip } from 'antd';
import { getColorTextLoadMap, removeDateHmsStr, tooltipLength } from '@/utils';
import pageStyles from '@/common/pageLayout.less';
import { Fragment } from 'react';
import { EditOutlined, EyeOutlined, CloseCircleOutlined, DeliveredProcedureOutlined } from '@ant-design/icons';
import { stateOfRendering } from '../common';
import { ManageCommonAPI } from '@/pages/type';
import { tableMoreBtnConfig } from '@/utils/myutilConfig';
import { ColumnsRenderFun, DictionaryRenderFun, formatDecimal } from '../../Acommon';

/**操作按钮的显示*/
const Operation = (curRes: Record<string, any>, operateFuns: AssetacquisitionManageAPI.IMaterialTableActionType, record: Record<string, any>) => {
  let operationArray: any = [];

  /** 一个按钮都没有时展示*/
  const Disable = (
    <Fragment key={record?.id + '--Disable'}>
      <Button style={{ color: '#000' }} className="manageBtntTxtStyle" type={'link'} size={'small'} disabled>
        --
      </Button>
    </Fragment>
  );

  /** 更多按钮配置 */
  const otherBtnConfig: ManageCommonAPI.TableMoreBtnConfigApi[] = [
    {
      icon: <EyeOutlined />,
      btnName: '查看',
      clickFnc: operateFuns,
      clickType: 'onView',
      // isVisible: curRes?.['/materialController/details/{params}']
      isVisible: false,
    },
    {
      icon: <EditOutlined />,
      btnName: '编辑',
      clickFnc: operateFuns,
      clickType: 'onEdit',
      isVisible: curRes?.['/materialController/edit'] && record?.state == 0,
      // isVisible: true
    },
    {
      icon: <DeliveredProcedureOutlined />,
      btnName: '申请',
      clickFnc: operateFuns,
      clickType: 'onApply',
      isVisible: curRes?.['/materialController/applyMaterial'] && record?.state == 0,
    },
    {
      icon: <CloseCircleOutlined style={{ color: 'red' }} />,
      btnName: <span style={{ color: 'red' }}>作废</span>,
      clickFnc: operateFuns,
      clickType: 'onCancel',
      isVisible: curRes?.['/materialController/cancel'] && (record?.state == 0 || record?.state == 2),
    },
  ];
  const ohterBtn = tableMoreBtnConfig(otherBtnConfig, record);
  operationArray = ohterBtn;
  operationArray = operationArray?.filter((itemBtn: any) => itemBtn);
  return operationArray && operationArray?.length > 0 ? operationArray : [Disable];
};

// Table表格的配置
const getTableColumns = (curRes: Record<string, any>, operateFuns: AssetacquisitionManageAPI.IMaterialTableActionType) => {
  const { onView } = operateFuns;
  return [
    {
      title: '资产名称', //0：起草 1：审核中 2：有效 3：作废
      dataIndex: 'assetName',
      key: 'assetName',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      // render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '资产类型',
      dataIndex: 'assetType',
      key: 'assetType',
      visible: true,
      width: 185,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.specInfo > b?.specInfo ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '资产状态',
      dataIndex: 'state',
      key: 'state',
      visible: true,
      width: 185,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.specInfo > b?.specInfo ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '使用人',
      dataIndex: 'userName',
      key: 'userName',
      visible: true,
      width: 185,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.specInfo > b?.specInfo ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '使用人部门',
      dataIndex: 'usePositionName',
      key: 'usePositionName',
      visible: true,
      width: 185,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.specInfo > b?.specInfo ? 1 : -1),
      render: (text: string | null) => ColumnsRenderFun({ text }),
    },
    {
      title: '是否盘点',
      dataIndex: 'isInventory',
      key: 'isInventory',
      visible: true,
      width: 130,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.supplyType > b?.supplyType ? 1 : -1),
      render: (text: string | null) => DictionaryRenderFun({ text }),
    },
    {
      title: '盘点结果',
      dataIndex: 'inventoryType',
      key: 'inventoryType',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      // render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '盘盈数量',
      dataIndex: 'surplusNum',
      key: 'surplusNum',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      // render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '盘盈金额',
      dataIndex: 'surplusSum',
      key: 'surplusSum',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      // render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '修改人',
      dataIndex: 'modifyerID',
      key: 'modifyerID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '修改人岗位',
      dataIndex: 'modifyPositionID',
      key: 'modifyPositionID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '修改人部门',
      dataIndex: 'modifyDepartmentID',
      key: 'modifyDepartmentID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '修改人单位',
      dataIndex: 'modifyCompanyID',
      key: 'modifyCompanyID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
      key: 'createTime',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '创建人',
      dataIndex: 'createrID',
      key: 'createrID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '创建人岗位',
      dataIndex: 'createPositionID',
      key: 'createPositionID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '创建人部门',
      dataIndex: 'createDepartmentID',
      key: 'createDepartmentID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '创建人单位',
      dataIndex: 'createCompanyID',
      key: 'createCompanyID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '作废时间',
      dataIndex: 'cancelTime',
      key: 'createDepartmentID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '作废人',
      dataIndex: 'cancelerID',
      key: 'cancelerID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '作废人岗位',
      dataIndex: 'cancelPositionID',
      key: 'cancelPositionID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '作废人部门',
      dataIndex: 'cancelDepartmentID',
      key: 'cancelDepartmentID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '作废人单位',
      dataIndex: 'cancelCompanyID',
      key: 'cancelCompanyID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '作废原因',
      dataIndex: 'cancelReason',
      key: 'cancelReason',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '备注',
      dataIndex: 'remark',
      key: 'remark',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '经办时间',
      dataIndex: 'ownTime',
      key: 'ownTime',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '经办人',
      dataIndex: 'ownerID',
      key: 'ownerID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '经办人岗位',
      dataIndex: 'ownPositionID',
      key: 'ownPositionID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '经办人部门',
      dataIndex: 'ownDepartmentID',
      key: 'ownDepartmentID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '经办人单位',
      dataIndex: 'ownCompanyID',
      key: 'ownCompanyID',
      visible: false,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    // {
    //   title: '操作',
    //   dataIndex: 'operation',
    //   key: 'operation',
    //   width: 230,
    //   visible: true,
    //   unDrag: true,
    //   fixed: 'right',
    //   render: (_: string, record: Record<string, any>) => {
    //     return (
    //       <Fragment>
    //         {
    //           <Button onClick={() => {}} type={'link'} size={'small'} icon={<EyeOutlined />}>
    //             查看
    //           </Button>
    //         }
    //         {
    //           <Button type={'link'} size={'small'} icon={<EditOutlined />} onClick={() => {}}>
    //             编辑
    //           </Button>
    //         }
    //       </Fragment>
    //     );
    //   },
    // },
  ];
};

export { getTableColumns };
